<script>
	export default {
		onLaunch: function() {
			let that = this;
			that.initApp();
		},
		onShow: function() {
			let that = this;
		},
		onHide: function() {
			let that = this;
		},
		onError: function(err) {
			let that = this;
			//全局错误监听
			console.error(err);
		},
		methods: {
			async initApp() {
				let that = this;
				console.log('App.vue:initApp');
				that.tui.initCache(function(appInit) {
					console.log('App.vue:appInit=>', appInit);
					// #ifdef H5
					if (that.tui.defToken) {
						that.tui.setCache('token', that.tui.defToken);
					}
					let pages = getCurrentPages();
					let currentPage = pages[pages.length - 1];
					if (that.tui.isLogin()) {
						that.tui.upDataUserInfo(function(res) {
							switch (res.status) {
								case -99:
								case -2:
									that.tui.removeUserInfo(function() {
										that.tui.urlOpen('/pages/public-login');
									});
									break;
								default:
									console.log('App.vue:userInfo=>', res.data);
									break;
							}
						});
					} else {
						if (!that.tui.inArray(currentPage.route, ['pages/public-register'])) {
							that.tui.urlOpen('/pages/public-login');
						}
					}
					// #endif	
				});
			},
		},
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
	@import './common/app.scss';
	@import './static/style/thorui-extend.css';

	page {
		background-color: rgb(245, 245, 245);
	}
</style>